﻿using System.Collections.Generic;

namespace Jayden.Dll.Core.Persistence.Models
{
	public class Index : IEnumerable<Property>
	{
		private Entity m_Entity;
		private string m_Name;
		private List<Property> m_Properties;

		public Index(Property property)
		{
			m_Properties = new List<Property>(new Property[] { property });
			m_Name = property.Name;
			m_Entity = property.Entity;
		}

		public Index(Entity entity, string name, params Property[] properties)
		{
			m_Entity = entity;
			m_Name = name;
			m_Properties = new List<Property>(properties);
			if (m_Name == null)
			{
				m_Name = string.Empty;
				foreach (Property p in m_Properties)
					m_Name += p.Name;
			}
		}

		public Entity Entity { get { return m_Entity; } }
		public string Name { get { return m_Name; } }
		public int Length { get { return m_Properties.Count; } }
		public Property this[int index] { get { return m_Properties[index]; } }

		public override string ToString()
		{
			return string.Format("{0}.{1}", m_Entity, m_Name);
		}


		public IEnumerator<Property> GetEnumerator() { return m_Properties.GetEnumerator(); }

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return m_Properties.GetEnumerator(); }
	}
}
